package manybymany;

import java.util.List;

import org.apache.ibatis.session.SqlSession;

import util.MybatisUtil;

public class SdtCourseDao {
	/**
	 * 查询哈哈选的课程有哪些
	 */
	public List<Course> findAllByName(String name) throws Exception{
		SqlSession sqlSession=null;
		try {
			 sqlSession=MybatisUtil.getSqlSession();
			return sqlSession.selectList("courseNamespace.findAllByName", name);
		} catch (Exception e) {
			e.printStackTrace();		
			throw e;
		}finally {
			MybatisUtil.closeSqlSession();
		}
		
	}
	
	/**
	 * 查询java课程有哪些学生
	 */
	public List<Sdt> findByName(String name) throws Exception{
		SqlSession sqlSession=null;
		try {
			 sqlSession=MybatisUtil.getSqlSession();
			return sqlSession.selectList("sdtNamespace.findByName",name);
		} catch (Exception e) {
			e.printStackTrace();		
			throw e;
		}finally {
			MybatisUtil.closeSqlSession();
		}
		
	}
	

	
	/**
	 * 测试
	 */
	
	public static void main(String[] args) throws Exception{
		SdtCourseDao dao=new SdtCourseDao();
		List<Course> courselist=dao.findAllByName("哈哈");
		System.out.println("哈哈选择的课程有"+courselist.size()+"个，他们分别是：");
		for (Course c : courselist) {
			System.out.println(c.getId()+":"+c.getName());
		}
		List<Sdt> sdtlist=dao.findByName("java");
		System.out.println("选java课程有"+sdtlist.size()+"个，他们分别是：");
		for (Sdt s : sdtlist) {
			System.out.println(s.getName());
		}
	}
	
	
}
	
